From: Matthieu Gallien Date: Fri, 30 May 2025 15:53:04 +0000 (+0200) Subject: fix(readonly): avoid changing permissions when not needed X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1^2~13^2~1^2~25^2~1 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success/%22http:/www.example.com/cgi/success?a=commitdiff_plain;h=2fcaf264442524627eb06feb2520541e0e3d6cf3;p=nextcloud-desktop.git fix(readonly): avoid changing permissions when not needed in FilePermissionsRestore, first checks the folder permissions before changing them will avoid useless call changing permissions when not needed Signed-off-by: Matthieu Gallien --- diff --git a/src/libsync/filesystem.cpp b/src/libsync/filesystem.cpp index 515d02b15..5603e4f4e 100644 --- a/src/libsync/filesystem.cpp +++ b/src/libsync/filesystem.cpp @@ -648,12 +648,13 @@ FileSystem::FilePermissionsRestore::FilePermissionsRestore(const QString &path, { try { - const auto stdStrPath = _path.toStdWString(); - _initialPermissions = FileSystem::isFolderReadOnly(stdStrPath) ? OCC::FileSystem::FolderPermissions::ReadOnly : OCC::FileSystem::FolderPermissions::ReadWrite; - if (_initialPermissions != temporaryPermissions) { + const auto &stdStrPath = _path.toStdWString(); + const auto fsPath = std::filesystem::path{stdStrPath}; + if ((temporaryPermissions == OCC::FileSystem::FolderPermissions::ReadOnly && !FileSystem::isFolderReadOnly(fsPath)) || + (temporaryPermissions == OCC::FileSystem::FolderPermissions::ReadWrite && FileSystem::isFolderReadOnly(fsPath))) { + FileSystem::setFolderPermissions(_path, temporaryPermissions); _rollbackNeeded = true; } - FileSystem::setFolderPermissions(_path, temporaryPermissions); } catch (const std::filesystem::filesystem_error &e) { diff --git a/test/testpermissions.cpp b/test/testpermissions.cpp index f04f14b00..5de4c4dd6 100644 --- a/test/testpermissions.cpp +++ b/test/testpermissions.cpp @@ -278,11 +278,7 @@ private slots: //4. File should be updated, that's tested by assertLocalAndRemoteDir QCOMPARE(currentLocalState.find("normalDirectory_PERM_CKDNV_/canBeModified_PERM_W_.data")->size, canBeModifiedSize + 1); -#if defined Q_OS_WINDOWS - QCOMPARE(currentLocalState.find("readonlyDirectory_PERM_M_/canBeModified_PERM_W_.data")->size, canBeModifiedSize); -#else QCOMPARE(currentLocalState.find("readonlyDirectory_PERM_M_/canBeModified_PERM_W_.data")->size, canBeModifiedSize + 1); -#endif //5. // the file should be in the server and local